<template>
	<view class="content">
		<!--头像 + 时间 -->
		<view class="content1 f-c-b">
			<view class="content1-left f-c-c">
				<image :src="baseUrl+dataObj.consumer.img" mode=""></image>
				<text>{{dataObj.consumer.name}}</text>
			</view>
			<view class="f25 themeColor">{{dataObj.time}}</view>
		</view>

		<!-- 具体内容 -->
		<view class="content2">
			<view class="content2-title themeColor f30">{{dataObj.title}}</view>
			<view class="content2-detail themeColor f30">{{dataObj.represent}}</view>

			<!-- 灰色框 -->
			<view class="content2-view themeColor f30">
				<view>{{status==='寻找失主'?'报酬金额':'金额'}}：￥{{dataObj.money}}</view>
				<view>类别：{{dataObj.goodstype.name}}</view>
				<view>手机号：**</view>
				<view>地点：{{dataObj.address}}</view>
				<view>{{status==='寻找失主'?'捡到时间':'丢失时间'}}：{{dataObj.goodtime}}</view>
			</view>

			<!-- 图片 -->
			<view class="content2-view-imgs f-co-c">
				<image @click="$preImg(dataObj.img,index)" v-for="(item,index) in dataObj.img" :src="item"
					mode="widthFix"></image>
			</view>

			<view class="content2-view-btn">
				<button v-if="status==='寻找失主'"
					@click="isMe=='true'?show=true:$to(`../immediate-payment/immediate-payment?id=${id}&money=${dataObj.money}`)"
					class="themeBac cwhite a">{{isMe=='true'?'删除':'立即支付'}}</button>

				<button v-else-if="status==='赏金'&&!toBeDetermined&&!retrieved&&determinedStatus==undefined||status==='赏金'&&myRelease&&!retrieved&&determinedStatus==undefined"
					@click="isMe=='true'?show=true:toGetMoney()" class="themeBac cwhite b">{{isMe=='true'?'删除':'领取赏金'}}</button>

				<button v-else-if="status==='赏金'&&toBeDetermined&&isMe&&determinedStatus==undefined" @click="toDetermine"
					class="themeBac cwhite">确定</button>

			</view>

			<u-modal v-model="show" :content="content" :show-title="false" :show-cancel-button="true" width="60%"
				:content-style="contentStyle" confirm-color="#373737" @confirm="toDelete()"></u-modal>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$u.baseUrl,
				dataObj: {},
				id: '',
				/* 上一层页面： 我的发布 + 非本人看 */
				isMe: true,
				/* 是否是 待确定 部分 */
				toBeDetermined: false,
				/* 是否是 已找回 部分 */
				retrieved: false,
				show: false,
				content: "是否确认删除",
				contentStyle: {
					fontSize: "34rpx",
					color: "#373737"
				},
				determinedStatus:0
			}
		},
		onLoad(e) {
			console.log(e);
			this.isMe = e.isMe
			this.status = e.status
			this.toBeDetermined = e.toBeDetermined
			this.retrieved = e.retrieved
			this.determinedStatus=e.determinedStatus

			this.id = e.id
			console.log(""+e.determinedStatus);

			this.goodInfo(e.id)
		},
		methods: {
			async goodInfo(id) {
				const res = await this.$u.api.goodInfo({
					id
				})
				console.log(res);
				this.dataObj = res.data
				this.dataObj.img = this.dataObj.img.split('|')
				this.dataObj.img=this.dataObj.img.map(item=>{
					return this.baseUrl+item
				})
				console.log(this.dataObj);
			},
			async release() {
				const res = await this.$u.api.release({
					id: this.vuex_user.id
				})
				console.log(res)
				this.$back(1)
			},
			async toDelete() {
				const res = await this.$u.api.relDel({
					id: this.id
				})
				res.success ? this.$redirec('../my-release/my-release') : null
			},
			async toDetermine() {
				const res = await this.$u.api.determineBtn({
					id: this.id
				})
				console.log(res);
				if (!res.success) {
					this.$u.toast(res.msg)
					return;
				}
				this.$redirec('../my-release/my-release')
			},
			async toGetMoney(){
				const res=await this.$u.api.pickerReward({
					consumer:this.vuex_user.id,
					goods:this.id
				})
				console.log(res);
				if(!res.success){
					this.$u.toast(res.msg)
					return
				}
				this.$tar('../message/message')
			}
		}
	}
</script>

<style>
	.content {
		padding: 30rpx;
	}

	.content1 {
		padding-bottom: 20rpx;
		border-bottom: 2rpx solid #373737;
	}

	.content1-left image {
		width: 50rpx;
		height: 50rpx;
		margin-right: 20rpx;
		border-radius: 50%;
	}


	.content2-title {
		font-weight: 700;
		margin: 20rpx 0;
	}

	.content2-view {
		background-color: #EBEBEB;
		margin: 30rpx 0;
		padding: 20rpx;
	}

	.content2-view view {
		line-height: 55rpx;
	}

	.content2-view-imgs image {
		margin-bottom: 10rpx;
	}

	.content2-view-btn {
		margin: 20rpx;
		padding: 0 40rpx;
	}

	.u-input {
		width: 100%;
	}

	.content2-detail {
		word-break: break-all;
		word-wrap: break-word;
		text-indent: 1rem;
	}
</style>
